package com.wjx.demo.collection

data class A(var i: Int)

fun main(args: Array<String>) {
    val l1 = listOf<Int>(1, 2, 4, 3)
    l1.forEach(::print)
    l1.forEach { x -> print(x) }
    val toList = l1.toList()  //返回只读list

    println(l1.any { it > 2 })
    println(l1.all { it > 2 })
    println(l1.count { it > 2 })

    val m1 = listOf(A(1), A(2)).flatMap { it -> mutableListOf(A(it.i)) }
    println(m1)
    val m2 = listOf(A(1), A(2)).map { A(it.i * 2) }
    println(m2)


}
